﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RWLib
{
    class SometimesReachableQuery: Query
    {

        private Formula condition;

        public SometimesReachableQuery(Tree _tree, Formula _cond)
        {
            condition = _cond;
            tree = _tree;
        }

        public override bool Run()
        {
             List<Node> children=tree.Root.Nodes;
             while (children.Any(c => c.Nodes.Count > 0)) {
                 children = children.Select(c=>c.Nodes).SelectMany(c=>c).ToList();
             }
             return children.Any(c=>condition.Eval(c.Fluents));
        }

    }
}
